import React from 'react';
import { Route } from 'react-router-dom';
import { getToken } from 'utils/storage';

export function AuthRoute(props) {
  const { path, component: Component } = props;
  return (
    <Route
      path={path}
      render={(props) => {
        // console.log('props', props);
        if (!!getToken()) {
          return <Component {...props} />;
        }
        props.history.push('/login');
      }}
    ></Route>
  );
}
